/**
 * 
 */
package servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import metier.Utilisateur;

/**
 * @author hozakan
 *
 */
public class Disconnect extends BaseServlet {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -2641162155935763864L;
	private static final Logger LOGGER = Logger.getLogger(Disconnect.class);

	/* (non-Javadoc)
	 * @see servlets.BaseServlet#specificDoGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected void specificDoGet(HttpServletRequest request,
			HttpServletResponse response) {
		Utilisateur user = (Utilisateur) request.getSession(false).getAttribute("user");
		if (user != null) {
			request.getSession(false).removeAttribute("user");
			if (LOGGER.isDebugEnabled()) {
				LOGGER.debug("L'utilisateur a été enlevé de la session");
			}
		} else {
			if (LOGGER.isDebugEnabled()) {
				LOGGER.debug("L'utilisateur n'existe pas");
			}
		}
		try {
			new GoToIndex().doGet(request, response);
		} catch (IOException e) {
			LOGGER.error("Une exception est intervenue durant la déconnexion : "+e.getMessage());
		} catch (ServletException e) {
			LOGGER.error("Une exception est intervenue durant la déconnexion : "+e.getMessage());
			e.printStackTrace();
		}
	}

	/* (non-Javadoc)
	 * @see servlets.BaseServlet#specificDoPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected void specificDoPost(HttpServletRequest request,
			HttpServletResponse response) {
		//Nothing to do
	}

}
